We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
In [16]:
let limit = 99999
let panOneNine = string(123456789)
let isPandigital n =
let n_sorted = new string (string(n).ToCharArray() |> Array.sort)
n_sorted = panOneNine.[0..((n_sorted.Length)-1)]
let divisors n =
let div_limit = (1 + (int(sqrt(double(n)))))
[2..div_limit]
|> List.filter (fun x -> n % x = 0)
let isPrimeNaive n =
divisors n
|> List.length = 0
seq { 1..123456789 }
|> Seq.filter isPandigital
|> Seq.filter isPrimeNaive
|> Seq.last
Out[16]:
In [ ]: